package com.moli.lumpSugar.common.interceptor;//package com.moli.lumpSugar.common.interceptor;
//
//import cn.hutool.core.collection.CollectionUtil;
//
//import com.moli.lumpSugar.common.domain.dto.RequestInfo;
//import com.moli.lumpSugar.common.exception.HttpErrorEnum;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.core.annotation.Order;
//import org.springframework.stereotype.Component;
//import org.springframework.web.servlet.HandlerInterceptor;
//
//import java.util.Map;
//import java.util.Objects;
//import java.util.Set;
//
///**
// * 黑名单的拦截器
// */
//@Order(3)
//@Slf4j
//@Component
//public class BlackUserInterceptor implements HandlerInterceptor {
//    @Autowired
//    private UserCache userCache;
//
//    @Override
//    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//        RequestInfo requestInfo = RequestHolder.get();
//        String ip = requestInfo.getIp();
//        Long uid = requestInfo.getUid();
//        Map<Integer, Set<String>> blackList = userCache.getBlackList();
//        if (isBlackUser(ip,blackList.get(BlackTypeEnum.IP.getType()))){
//            HttpErrorEnum.ACCESS_DENIED.sendHttpError(response);
//            return false;
//        }
//        if (isBlackUser(uid,blackList.get(BlackTypeEnum.UID.getType()))){
//            HttpErrorEnum.ACCESS_DENIED.sendHttpError(response);
//            return false;
//        }
//        return true;
//    }
//
//    private Boolean isBlackUser(Object target,Set<String> blackList) {
//        if (Objects.isNull(target) || CollectionUtil.isEmpty(blackList)){
//            return false;
//        }
//        return blackList.contains(target.toString());
//    }
//
//}